<? // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' ); ?>

<script type="text/javascript" src="/media/system/js/jcarousellite.js"></script>
<script type="text/javascript" src="/media/system/js/jquery.mousewheel.js"></script>
<script type="text/javascript">
	jQuery(document).ready(
		function(){
			var size = jQuery('.leader_carousel ul li').size();
			if(size > 2)
				size = 2;
			
			jQuery('.leader_carousel').jCarouselLite({
				btnNext: ".leader_next",
				btnPrev: ".leader_prev",
				visible: size,
				mouseWheel: true
			});
		}
	);
	
</script>
<link rel="stylesheet" type="text/css" href="<?= JURI::base(true) ?>/modules/mod_pbny_weekly_leaders/tmpl/styles.css"/> 

<h4 style="margin-bottom:5px">WEEKLY LEADERS</h4>
<div style="float:left;">
	<input type="button" class="leader_prev button" value="<" />
</div>
<div style="float:left;">
<div class="leader_carousel">
	<ul>
<? 	$data = array('points' => $points, 'rebounds' => $rebounds, 'assists' => $assists, 'steals' => $steals, 'blocks' => $blocks);
	foreach($divisions as $division):
		foreach($data as $title => $division_stats): 
			$stats = $division_stats[$division->id];
		?>
			<li style="height:220px">
				<table class="table" style="width:445px;">
					<tr>
						<td colspan="3" class="cell_key"><?= strtoupper($title)." - $division->name" ?></td>
					</tr>
					<? if(empty($stats)): ?>
						<tr>
							<td class="cell_key"><?= JText::_("No weekly top $title") ?></td>
						</tr>
					<? endif; ?>
					<? 	$count  = 0;
						$highest= 0;
						$flag   = true;
						foreach($stats as $player_id => $stat):
							
							if($count>4)	#limit to five players only
								break;
								
							if($stat[$title] > $highest) #benchmark highest score
								$highest = $stat[$title];
								
							$player = $players[$division->id][$player_id];
							$name   = $player->fullname.' #'.$player->jersey_number.' '.$teams[$division->id][$player->team_id]->abbr;
							
							$pic    = null;
							if(isset($player->pic->pic))
								$pic    = $player->pic->pic;
							
							if($stat[$title] == $highest && $count == 0): ?>
							
								<tr>
									<td rowspan="4" align="center"><img src="<?= $pic ?>" width="100px" height="100px" alt="no image"/></td>
									<td colspan="2" class="cell_value"><?= $name ?></td>
								</tr>
								<tr>
									<td class="cell_key" style="text-align:left;"><?= strtoupper($title[0]).'PG' ?></td>
									<td class="cell_value"><?= number_format($stat[$title]/$stat['gp'], 1) ?></td>
								</tr>
								<tr>
									<td class="cell_key" style="text-align:left;">TOTAL</td>
									<td class="cell_value"><?= $stat[$title] ?></td>
								</tr>
					
					<?		else: ?>
								<? if($flag): ?>
									<tr>
										<td class="cell_key"><?= strtoupper($title[0]).'PG' ?></td>
										<td class="cell_key">TOTAL</td>
									</tr>		
								<? $flag = false;
								   endif ?>
								<tr>
									<td class="cell_key" style="text-align:left;padding-left:60px"><?= $name ?></td>
									<td class="cell_value"><?= number_format($stat[$title]/$stat['gp'], 1) ?></td>
									<td class="cell_value"><?= $stat[$title] ?></td>
								</tr>
					<?	  	endif;
							
							$count++;
						endforeach ?>
				</table>
			</li>
	<? 	endforeach;
	endforeach ?>
	</ul>	
</div>
</div>
<div style="float:right;">
	<input type="button" class="leader_next button" value=">"/>
</div>
<div class="clear"></div>